//LuoFeng Nanami ver.
#include<bits/stdc++.h>
#define rll register int
#define F(i, a, b) for(rll i = a; i <= b; i++)
#define Fdn(i, a, b) for(rll i = a; i >= b; i--)
#define ld long double
#define pii pair<int, int>
#define fi first
#define se second

using namespace std;
const int inf = 0x3f3f3f3f, mod = 1e9 + 7, _mod = 998244353;
const int maxn = 2e5 + 7;

int _;
int n;
int a[maxn];
int r[maxn], totr;
int b[maxn], totb;
//int f[101][101][101][101];

inline int check() {
    int ret = 0;
    F(i, 2, totr) if(r[i - 1] == r[i]) ret += r[i];
    F(i, 2, totb) if(b[i - 1] == b[i]) ret += b[i];
    return ret;
}

inline void init() {
    F(i, 1, n) {
        if(rand() % 2) r[++totr] = a[i];
        else b[++totb] = b[i];
    }
}

int ans57;
inline int SA() {
    int res = 0;
    for(ld temp = 1899; temp > (1e-12); temp *= 0.98) {
        //cout << temp << '\n';
        totr = totb = 0; 
        init();
        int _res = check(); int del = res - _res;
        if(del < 0) res = _res;
        else if(exp((ld)-del / temp) * RAND_MAX > rand()) res = _res;
    }
    return res;
}// stO SA Orz

inline void Sub57(int ce) {
    ans57 = 0;
    while(clock() / CLOCKS_PER_SEC < (ld)ce * 1.97 / (ld)_) ans57 = max(ans57, SA());
    cout << ans57 << '\n';
}

int ans14;
inline void dfs(int x) {
    if(x == n + 1) {
        ans14 = max(ans14, check());
        return ;
    }
    r[++totr] = a[x];
    dfs(x + 1);
    totr--;
    b[++totb] = a[x];
    dfs(x + 1);
    totb--;
}
inline void Sub14() {
    ans14 = 0;
    totr = totb = 0;
    dfs(1);
    cout << ans14 << '\n';
}

int main() {
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);

    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);

    srand(time(0));
    cin >> _;
    int ce = 0;
    while(_--) {
        ce++;
        totr = totb = 0;
        cin >> n;
        F(i, 1, n) cin >> a[i];
        if(n <= 15) { Sub14(); continue; }
        /*else if(n <= 100) {
            memset(f, -0x3f, sizeof f);
            F(i, 1, 100) f[1][a[1]][0][i] = 0;
            F(i, 1, 100) f[0][i][1][a[1]] = 0;
            F(i, 2, n) {
                F(j, 0, i) {
                    if(j == i) F(i1, 1, 100) F(i2, 1, 100) 
                        f[j][a[i]][0][i2] = f[j - 1][i1][0][i2] + (a[i] == i1 ? a[i] : 0);
                    else if(j == 0) 
                    else {
                        F(i1, 1, 100) F(i2, 1, 100) 
                        f[j][a[i]][i - j][i2] = max(f[j][a[i]][i - j][i2], f[j - 1][i1][i - j][i2] + (a[i] == i1 ? a[i] : 0));
                        F(i1, 1, 100) F(i2, 1, 100)
                        f[j][a[i]][i - j][i2] = max(f[j][a[i]][i - j][i2], f[j][a[i]][i - j - 1][i1] + (i1 == i2 ? i1 : 0));
                        F(i1, 1, 100) F(i2, 1, 100)
                        f[j][i1][i - j][a[i]] = max(f[j][i1][i - j][a[i]], f[j - 1][i2][i - j][a[i]])
                    }
                }
            }
        }*/
    }

    return 0;
}